home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-cm-cm.cc < prev    next >
C/C++ Source or Header  |  1997-01-24  |  8KB  |  249 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-cx-mat.h"
  34. #include "ov-typeinfo.h"
  35. #include "op-cm-cm.h"
  36. #include "ops.h"
  37. #include "xdiv.h"
  38. #include "xpow.h"
  39.  
  40. // complex matrix by complex matrix ops.
  41.  
  42. static octave_value
  43. add (const octave_value& a1, const octave_value& a2)
  44. {
  45.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  46.  
  47.   return octave_value (v1.complex_matrix_value ()
  48.                + v2.complex_matrix_value ());
  49. }
  50.  
  51. static octave_value
  52. sub (const octave_value& a1, const octave_value& a2)
  53. {
  54.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  55.  
  56.   return octave_value (v1.complex_matrix_value ()
  57.                - v2.complex_matrix_value ());
  58. }
  59.  
  60. static octave_value
  61. mul (const octave_value& a1, const octave_value& a2)
  62. {
  63.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  64.  
  65.   return octave_value (v1.complex_matrix_value ()
  66.                * v2.complex_matrix_value ());
  67. }
  68.  
  69. static octave_value
  70. div (const octave_value& a1, const octave_value& a2)
  71. {
  72.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  73.  
  74.   return xdiv (v1.complex_matrix_value (), v2.complex_matrix_value ());
  75. }
  76.  
  77. static octave_value
  78. pow (const octave_value&, const octave_value&)
  79. {
  80.   error ("can't do A ^ B for A and B both matrices");
  81.   return octave_value ();
  82. }
  83.  
  84. static octave_value
  85. ldiv (const octave_value& a1, const octave_value& a2)
  86. {
  87.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  88.  
  89.   return xleftdiv (v1.complex_matrix_value (), v2.complex_matrix_value ());
  90. }
  91.  
  92. #define BOOL_OP(OP, ONE_EMPTY_RESULT, TWO_EMPTY_RESULT) \
  93.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (), \
  94.          ComplexMatrix, m2, v2.complex_matrix_value (), \
  95.          real (m1 (i, j)) OP real (m2 (i, j)), #OP, \
  96.          ONE_EMPTY_RESULT, TWO_EMPTY_RESULT)
  97.  
  98. static octave_value
  99. lt (const octave_value& a1, const octave_value& a2)
  100. {
  101.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  102.  
  103.   BOOL_OP (<, Matrix (), Matrix ());
  104. }
  105.  
  106. static octave_value
  107. le (const octave_value& a1, const octave_value& a2)
  108. {
  109.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  110.  
  111.   BOOL_OP (<=, Matrix (), Matrix ());
  112. }
  113.  
  114. static octave_value
  115. eq (const octave_value& a1, const octave_value& a2)
  116. {
  117.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  118.  
  119.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (),
  120.          ComplexMatrix, m2, v2.complex_matrix_value (),
  121.          m1 (i, j) == m2 (i, j), "==",
  122.          0.0, 1.0);
  123. }
  124.  
  125. static octave_value
  126. ge (const octave_value& a1, const octave_value& a2)
  127. {
  128.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  129.  
  130.   BOOL_OP (>=, Matrix (), Matrix ());
  131. }
  132.  
  133. static octave_value
  134. gt (const octave_value& a1, const octave_value& a2)
  135. {
  136.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  137.  
  138.   BOOL_OP (>, Matrix (), Matrix ());
  139. }
  140.  
  141. static octave_value
  142. ne (const octave_value& a1, const octave_value& a2)
  143. {
  144.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  145.  
  146.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (),
  147.          ComplexMatrix, m2, v2.complex_matrix_value (),
  148.          m1 (i, j) != m2 (i, j), "!=",
  149.          1.0, 0.0);
  150. }
  151.  
  152. static octave_value
  153. el_mul (const octave_value& a1, const octave_value& a2)
  154. {
  155.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  156.  
  157.   return octave_value (product (v1.complex_matrix_value (),
  158.                 v2.complex_matrix_value ()));
  159. }
  160.  
  161. static octave_value
  162. el_div (const octave_value& a1, const octave_value& a2)
  163. {
  164.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  165.  
  166.   return octave_value (quotient (v1.complex_matrix_value (),
  167.                  v2.complex_matrix_value ()));
  168. }
  169.  
  170. static octave_value
  171. el_pow (const octave_value& a1, const octave_value& a2)
  172. {
  173.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  174.  
  175.   return elem_xpow (v1.complex_matrix_value (), v2.complex_matrix_value ());
  176. }
  177.  
  178. static octave_value
  179. el_ldiv (const octave_value& a1, const octave_value& a2)
  180. {
  181.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  182.  
  183.   return octave_value (quotient (v2.complex_matrix_value (),
  184.                  v1.complex_matrix_value ()));
  185. }
  186.  
  187. static octave_value
  188. el_and (const octave_value& a1, const octave_value& a2)
  189. {
  190.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  191.  
  192.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (),
  193.          ComplexMatrix, m2, v2.complex_matrix_value (),
  194.          m1 (i, j) != 0.0 && m2 (i, j) != 0.0, "&",
  195.          Matrix (), Matrix ());
  196. }
  197.  
  198. static octave_value
  199. el_or (const octave_value& a1, const octave_value& a2)
  200. {
  201.   CAST_BINOP_ARGS (const octave_complex_matrix&, const octave_complex_matrix&);
  202.  
  203.   MX_MX_BOOL_OP (ComplexMatrix, m1, v1.complex_matrix_value (),
  204.          ComplexMatrix, m2, v2.complex_matrix_value (),
  205.          m1 (i, j) != 0.0 || m2 (i, j) != 0.0, "|",
  206.          Matrix (), Matrix ());
  207. }
  208.  
  209. static octave_value
  210. assign (octave_value& a1, const octave_value_list& idx,
  211.     const octave_value& a2)
  212. {
  213.   CAST_BINOP_ARGS (octave_complex_matrix&, const octave_complex_matrix&);
  214.  
  215.   v1.assign (idx, v2.complex_matrix_value ());
  216.   return octave_value ();
  217. }
  218.  
  219. void
  220. install_cm_cm_ops (void)
  221. {
  222.   INSTALL_BINOP (add, octave_complex_matrix, octave_complex_matrix, add);
  223.   INSTALL_BINOP (sub, octave_complex_matrix, octave_complex_matrix, sub);
  224.   INSTALL_BINOP (mul, octave_complex_matrix, octave_complex_matrix, mul);
  225.   INSTALL_BINOP (div, octave_complex_matrix, octave_complex_matrix, div);
  226.   INSTALL_BINOP (pow, octave_complex_matrix, octave_complex_matrix, pow);
  227.   INSTALL_BINOP (ldiv, octave_complex_matrix, octave_complex_matrix, ldiv);
  228.   INSTALL_BINOP (lt, octave_complex_matrix, octave_complex_matrix, lt);
  229.   INSTALL_BINOP (le, octave_complex_matrix, octave_complex_matrix, le);
  230.   INSTALL_BINOP (eq, octave_complex_matrix, octave_complex_matrix, eq);
  231.   INSTALL_BINOP (ge, octave_complex_matrix, octave_complex_matrix, ge);
  232.   INSTALL_BINOP (gt, octave_complex_matrix, octave_complex_matrix, gt);
  233.   INSTALL_BINOP (ne, octave_complex_matrix, octave_complex_matrix, ne);
  234.   INSTALL_BINOP (el_mul, octave_complex_matrix, octave_complex_matrix, el_mul);
  235.   INSTALL_BINOP (el_div, octave_complex_matrix, octave_complex_matrix, el_div);
  236.   INSTALL_BINOP (el_pow, octave_complex_matrix, octave_complex_matrix, el_pow);
  237.   INSTALL_BINOP (el_ldiv, octave_complex_matrix, octave_complex_matrix, el_ldiv);
  238.   INSTALL_BINOP (el_and, octave_complex_matrix, octave_complex_matrix, el_and);
  239.   INSTALL_BINOP (el_or, octave_complex_matrix, octave_complex_matrix, el_or);
  240.  
  241.   INSTALL_ASSIGNOP (octave_complex_matrix, octave_complex_matrix, assign);
  242. }
  243.  
  244. /*
  245. ;;; Local Variables: ***
  246. ;;; mode: C++ ***
  247. ;;; End: ***
  248. */
  249.